package com.foreknow.view;

import com.foreknow.model.Business;
import com.foreknow.service.BusinessService;
import com.foreknow.service.impl.BusinessServiceImpl;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class ShowGetById extends JFrame {
    String[][] business;

    private JPanel contentPane;
    private JTable table;

    /**
     * Launch the application.
     */
    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    ShowGetById frame = new ShowGetById();
                    frame.setVisible(true);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }

    /**
     * Create the frame.
     */
    public ShowGetById() {
        business= new String[1][7];
        setTitle("\u67E5\u8BE2\u7ED3\u679C");
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setBounds(100, 100, 644, 445);
        contentPane = new JPanel();
        contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
        setContentPane(contentPane);
        contentPane.setLayout(null);

        table = new JTable();

                String text = new GetQueryById().getId();
                int id = Integer.parseInt(text);
                BusinessService businessService=new BusinessServiceImpl();
                Object b =businessService.getQueryById(id);
               Business b1= (Business) b;
                business[0][0]=b1.getBusinessId()+"";
                business[0][1]=b1.getPassword();
                business[0][2]=b1.getBusinessName();
                business[0][3]=b1.getBusinessAddress();
                business[0][4]=b1.getBusinessExplain();
                business[0][5]=b1.getStarPrice()+"";
                business[0][6]=b1.getDeliveryPrice()+"";
//                GetQueryById.this.validate();
                table.updateUI();
                System.out.println("查询");
                contentPane.updateUI();
//                GetQueryById getQueryById=new GetQueryById();
        table.setModel(new DefaultTableModel(
               business,
                new String[] {
                        "New column", "New column", "New column", "New column", "New column", "New column", "New column"
                }
        ));
        table.setBounds(33, 40, 550, 195);
        contentPane.add(table);

        JButton btnNewButton = new JButton("\u8FD4\u56DE");
        btnNewButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {

                System.out.println("返回");
                MainWindow mainWindow = new MainWindow();
                mainWindow.setVisible(true);
                ShowGetById.this.dispose();
            }
        });
        btnNewButton.setBounds(222, 312, 113, 27);
        contentPane.add(btnNewButton);
    }

}
